from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from try_mysql import *
from PyQt5.uic import loadUiType
import begin_py
from movie_record_manage_ui import Ui_Movie_record
import sys
ui, _ = loadUiType('delete_user.ui')

class Delete_App(QMainWindow, ui):
    #定义构造
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        #self.handle_ui_change()
        self.handle_buttons()
        self.handle_buttons()
        self.password.setEchoMode(QLineEdit.Password)
        self.show()

    def handle_buttons(self):
        self.delete_user.clicked.connect(self.Delete_user)
        self.delete_cancel.clicked.connect(self.Close)

    def Delete_user(self):
        conn = get_conn()
        cur = conn.cursor()
        StaffName = self.staff_name.text()
        StaffNum = self.staff_num.text()
        StaffPassword = self.password.text()
        if (StaffNum == "" or StaffPassword == "" or StaffName==""):
            QMessageBox.information(self, "提示", "主要字段不得为空", QMessageBox.Yes, QMessageBox.Yes)
            return
        else:
            warning = QMessageBox.warning(self, "提示", "你确定注销该用户吗?", QMessageBox.Yes | QMessageBox.No)
            if warning == QMessageBox.Yes:
                sql1 = "delete from user where StaffNum=%s and StaffName=%s"
                cur.execute(sql1, (StaffNum, StaffName))
                conn.commit()
                close_conn(conn, cur)
                print(QMessageBox.information(self, "提醒", "注销成功", QMessageBox.Yes, QMessageBox.Yes))
                self.Back = begin_py.Begin_App()
                self.close()
                self.Back.show()
            return


    def Close(self):
        self.Back = begin_py.Begin_App()
        self.close()
        self.Back.show()


    def clearEdit(self):
        self.staff_name.clear()
        self.staff_num.clear()
        self.password.clear()



def main():
    app = QApplication([])
    window = Delete_App()
    window.show()
    app.exec_()

if __name__ == '__main__':
    main()